package lesson3.slides.net;
import java.io.*;
import java.net.*;

public class TimeServiceExample {
    
    //static String host="nist1-ny.ustiming.org";
    //static String host="www.nist.gov";
    //static String host="time-a.nist.gov";
    //static String host="time-b.nist.gov";
    
    static String host="localhost";
    
    //static int port=13;
    static int port=9876;

    public static void main(String[] args) {
        try {
            Socket s = new Socket(host, port);
            InputStream istrm = s.getInputStream();
            BufferedReader input = new BufferedReader(
                    new InputStreamReader(istrm));
            String line = null;
            
            while((line=input.readLine())!=null){
                System.out.println(line);
            }
            /*
            do {
                line = input.readLine();
                if (line == null) {
                    System.out.println("Nothing to read");
                    break;
                }
                System.out.println(line);
            } while (line != null);
            */
            s.close();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }
}
